package enumdemo;

public enum TestEnum {
    RED(0,"RED"),
    WHITE(1,"WHITE"),
    GREEAN(2,"GREEAN"),
    BLACK(3, "BLACK");
    public int ordinal;
    public String color;

    TestEnum(int ordinal, String color) {
        this.ordinal = ordinal;
        this.color = color;
    }

    public static void main(String[] args){
        TestEnum[] testEnums= TestEnum.values();//以数组形式返回枚举类型的所有成员
        for(int i=0;i< testEnums.length;i++){
            System.out.println(testEnums[i]+" : "+testEnums[i].ordinal);
            //获取枚举成员的索引位置
        }
        TestEnum testEnum=TestEnum.valueOf("WHITE");//将普通字符串转换为枚举实例
        System.out.println(testEnum);
        System.out.println(WHITE.compareTo(BLACK));//比较两个枚举成员在定义时的顺序


    }
    public static void main1(String[] args){
        TestEnum testEnum=BLACK;
        switch (testEnum){
            case RED:
                System.out.println(RED);
                break;
            case BLACK:
                System.out.println(BLACK);
                break;
            case WHITE:
                System.out.println(WHITE);
                break;
            case GREEAN:
                System.out.println(GREEAN);
                break;
            default:
                System.out.println("无法查找...");
                break;
        }
    }

}
